package com.application.outdoor.adapter;

import java.util.List;

import com.application.Activity.R;


import android.content.Context;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ScaleDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ThirdPartyAppInfoAdapter extends BaseAdapter {

	private Context context;
	private List<ResolveInfo> data;
	LayoutInflater inflater;
	private static class ViewHolder {
		ImageView imIcon;
		TextView txtName;
//		Button btnDownload;
	}
	public ThirdPartyAppInfoAdapter(Context context,List<ResolveInfo> data){
		this.context = context;
		this.data = data;
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int index) {
		return data.get(index);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		View rs=view;
		if(rs==null){
			rs=inflater.inflate(R.layout.od_row_third_party_info, null);
			ViewHolder holder=new ViewHolder();
			holder.imIcon=(ImageView)rs.findViewById(R.id.imIcon);
			holder.txtName=(TextView)rs.findViewById(R.id.txtName);
			rs.setTag(holder);
		}
		ViewHolder holder=(ViewHolder)rs.getTag();
		String appName=data.get(position).activityInfo.name;
		holder.txtName.setText(appName.substring(appName.lastIndexOf(".")+1,appName.length()));
//		holder.imIcon.setImageResource(data.get(position).activityInfo.icon);
		
		BitmapDrawable icon=(BitmapDrawable) data.get(position).loadIcon(context.getPackageManager());
		Bitmap bm=icon.getBitmap();
		Bitmap bmRs=Bitmap.createScaledBitmap(bm, 32, 32, true);
		
		holder.imIcon.setImageBitmap(bmRs);
		return rs;
	}

}
